﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;

namespace UniMana.Data
{
    public class Training_Score_TaskInputInfo
    {
        #region /*Không thay đổi*/
        public bds m_bds = new bds();
        public void Save()
        {
            m_data.m_DCSave.SubmitChanges();
        }
        public void Delete()
        {
            m_bds.DeleteCurrent();
        }
        #endregion /*Không thay đổi*/
        private DBMain m_data = new DBMain();
        private bool m_bExist = true;
        #region [Properties - Thuộc tính]
        public Training_Score_TaskInput Properties
        {
            get { return m_bds.Current as Training_Score_TaskInput; }
        }
        #endregion

        public Training_Score_TaskInputInfo(int _iTraining_Score_TaskInputKey = -1, bool _bInput = true)
        {
            var IQuery = m_data.m_DCSave.Training_Score_TaskInputs.Where(p => p.Training_Score_TaskInputKey == _iTraining_Score_TaskInputKey);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            this.m_bExist = true;
            if (Row == null)
            {
                this.m_bExist = false;
                Row = new Training_Score_TaskInput();
                Row.Input = _bInput;
                m_bds.Add(Row);
            }
        }
        public Training_Score_TaskInputInfo(Guid _iPersonnel_Personnel, int _iTraining_Subject_ClassKey, bool _bInput = true)
        {
            var IQuery = m_data.m_DCSave.Training_Score_TaskInputs.Where(p => p.Personnel_PersonnelKey == _iPersonnel_Personnel && p.Training_Subject_ClassKey == _iTraining_Subject_ClassKey && p.Input == _bInput);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            this.m_bExist = true;
            if (Row == null)
            {
                this.m_bExist = false;
                Row = new Training_Score_TaskInput();
                Row.Input = _bInput;
                m_bds.Add(Row);
            }
        }
        public Training_Score_TaskInputInfo(Guid _iPersonnel_Personnel, int _iTraining_Subject_ClassKey, DateTime _dteNow, bool _bInput = true)
        {
            var IQuery = m_data.m_DCSave.Training_Score_TaskInputs.Where(p => p.Personnel_PersonnelKey == _iPersonnel_Personnel && p.Training_Subject_ClassKey == _iTraining_Subject_ClassKey && p.Input == _bInput && p.Date.Value.AddDays(p.Period.Value) > _dteNow && (p.Lock == false || p.Lock == null));
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            this.m_bExist = true;
            if (Row == null)
            {
                this.m_bExist = false;
                Row = new Training_Score_TaskInput();
                Row.Input = _bInput;
                m_bds.Add(Row);
            }
        }
        public bool ExistInDataBase
        {
            get { return this.m_bExist; }
        }
    }
}
